﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.Xna.Framework;

namespace WindowsGame4
{
    class Explosion : Object
    {
        private String idEmissor;
        private Boolean disable;
        public Explosion(String id, Position2D position, Model model, String idEmissor) : base(id, position, model)
        {
            type = Object.TypeObject.explosion;
            this.idEmissor = idEmissor;
            disable = false;
        }

        public String IdEmissor
        {
            get { return idEmissor; }
            set { idEmissor = value; }
        }

        public Boolean Disable
        {
            get { return disable; }
            set { disable = value; }
        }

        public Object checkColision(ArrayList type, ArrayList ignoreObjects)
        {
            GameInfo gameInfo = GameInfo.getInstance();
            for (int i = 0; i < type.Count; i++)
            {
                Dictionary<String, Object> aux = gameInfo.getObjects((String)type[i]);
                foreach (KeyValuePair<String, Object> j in aux)
                {
                    Object obj = j.Value;
                    if (ignoreObjects.Contains(obj.Id) == false)
                    {
                        Rectangle rectObj = obj.Colision;

                        if (obj.Type == Object.TypeObject.player || obj.Type == Object.TypeObject.enemy)
                        {
                            // Use wheel to the colision
                            if (obj.Direction != null)
                            {
                                if (obj.Direction.getDirection() == "left" || obj.Direction.getDirection() == "right")
                                    rectObj = obj.HorizontalColision;
                                if (obj.Direction.getDirection() == "up" || obj.Direction.getDirection() == "down")
                                    rectObj = obj.VerticalColision;
                            }
                        }

                        Rectangle a = new Rectangle(obj.Position.X + rectObj.X, obj.Position.Y + rectObj.Y, rectObj.Width, rectObj.Height);
                        Rectangle b = new Rectangle(this.Position.X + this.Colision.X, this.Position.Y + this.Colision.Y, this.Colision.Width, this.Colision.Height);
                        if (Game1.modeDebug)
                        {
                            Game1.spriteBatch.Begin();
                            Game1.spriteBatch.Draw(Game1.textColision, a, Color.White);
                            Game1.spriteBatch.Draw(Game1.textColision, b, Color.White);
                            Game1.spriteBatch.End();
                        }
                        if (gameInfo.rectangleColission(a, b))
                            return obj;
                    }
                }
            }
            return null;
        }
    }
}
